package org.example.Day6.JDK8;

import org.example.Day4.Student;

import java.util.*;
import java.util.stream.Collectors;

public class StreamTest3 {
    public static void main(String[] args){
        //数据流的终结
        List<Student> students = new ArrayList<>();
        Student s1 = new Student("蜘蛛精",  172.5,26);
        Student s2 = new Student("蜘蛛精",  172.5,26);
        Student s3 = new Student("紫霞",  167.6,23);
        Student s4 = new Student("⽩晶晶",  169.0,25);
        Student s5 = new Student("⽜魔王",  183.3,35);
        Student s6 = new Student("⽜夫⼈",  168.5,34);
        Collections.addAll(students, s1, s2, s3, s4, s5, s6);
        //身高超过168有多少人
        long size = students.stream().filter(s->s.getHeight()>168).count();
        System.out.println(size);

        //找出身高最高的人 并输入
        Student s7 = students.stream().max((o1,o2)->Double.compare(o1.getHeight(),o2.getHeight())).get();
        System.out.println(s7);

        //找出身高最矮的输出
        Student s8 = students.stream().min(((o1, o2) -> Double.compare(o1.getHeight(),o2.getHeight()))).get();
        System.out.println(s8);

        //将身高高于170的人重新写入一个集合
        List<Student> students1 = students.stream().filter(s->s.getHeight()>170).collect(Collectors.toList());
        System.out.println(students1);

        //用set集合
        Set<Student> students2 = students.stream().filter(s->s.getHeight()>170).collect(Collectors.toSet());
        System.out.println(students2);

        //身高超过170的学生放进Map集合中
        Map<String,Double> map = students.stream().filter(s->s.getHeight()>170)
                .distinct().collect(Collectors.toMap(s->s.getName(),s->s.getHeight()));
        System.out.println(map);

        //Arr集合
        Student[] arr = students.stream().filter(a->a.getHeight()>170).toArray(len ->new Student[len]);
        System.out.println(Arrays.toString(arr));
    }
}
